package com.rainner.admin.server;

import java.sql.SQLException;
import java.util.List;

import com.rainner.admin.javabean.RoleBean;
import com.rainner.admin.util.dbutil.BaseService;

public class RoleServer extends BaseService<RoleBean> {
	/**
	 * 返回角色详细信息
	 * 
	 * @param rows
	 *            行数
	 * @param page
	 *            页码
	 * @return
	 * @throws SQLException
	 */
	public List<RoleBean> manageData(long rows, long page) throws SQLException {
		String sqlSelect = "select * from Role limit ?,?";
		return super.query(sqlSelect, (page - 1) * rows, rows);
	}

	/**
	 * 返回角色总数量
	 * 
	 * @return
	 * @throws SQLException
	 */
	public long manageDataCount() throws SQLException {
		String sqlSelect = "select COUNT(1) from Role";
		return super.counts(sqlSelect);
	}

	/**
	 * 根据角色ID删除操作员
	 * @param roleId
	 * @return
	 * @throws SQLException
	 */
	public boolean manageDelData(String roleId) throws SQLException {
		String sqlSelect = "select COUNT(1) from Role where roleId = ? ";
		if(super.counts(sqlSelect,roleId) >0){
			String sqlDelete = "delete  from Role where RoleID = ?";
			return super.update(sqlDelete, roleId);
		}
		else {
			return false;
		}
	}

	/**
	 * 新增角色
	 * @param roleId
	 * @param roleName
	 * @return
	 * @throws Exception
	 */
	public boolean manageAddData(String roleId,String roleName) throws Exception {
		String sqlSelect = "select COUNT(1) from Role where roleId = ? and roleName = ?";
		if(super.counts(sqlSelect,roleId,roleName) < 1){
			String sqlAdd = "insert into Role(RoleID,RoleName) values(?,?)";
			return super.update(sqlAdd, roleId, roleName);
		}
		else {
			return false;
		}
	}
}
